# name : dplyr&purrr rowwise.lag.func by group
# key : group.rowwise.lag.func
# key : dplyr.group.rowwise.lag.func
# key : rowwise.lag.func.group
# key : rowwise.lag.fillin.group
# contributor: Shuguang Sun
# --
${1:fill_in} <- function(prev, new, growth = 0.03) {
  if_else(!is.na(new), new, prev * (1 + growth))
}

${2:dt} |>
group_by(${3:id}) |>
arrange(${4:index}, .by_group = TRUE) |>
mutate(${5:newvar} = purrr::accumulate(${6:var}, $1)) |>
ungroup()